package com.tiwi.gmbdr;

import com.tiwi.gmbdr.OpenHelper.QuestionOpenHelper;
import com.tiwi.gmbdr.constant.Global;
import com.tiwi.gmbdr.model.Question;
import com.tiwi.gmbdr.sample.SampleData;
import com.tiwi.gmbdr.tools.Tool;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;

public class UpdateSoalTask extends AsyncTask<Void, Void, String> {

	private ProgressDialog progressDialog;
	private Activity activity;
	private String messageWait;

	public UpdateSoalTask(Activity activity) {
		this.activity = activity;
		this.messageWait = "Updating...";

	}

	@Override
	protected void onPreExecute() {
		progressDialog = ProgressDialog.show(this.activity, "",
				this.messageWait, true);

	}

	@Override
	protected String doInBackground(Void... arg0) {

		String soal = SampleData.soal;
		QuestionOpenHelper questionOpenHelper = new QuestionOpenHelper(activity); 
		
		String[] arrSoal = Tool.split(soal, Global.DELIMETER_ROW);
		
		for (int i = 0; i < arrSoal.length; i++) {
			
			Question bean  = new Question(arrSoal[i]);
			questionOpenHelper.insertQuestion(bean);
			
		}
		
		return null;
	}

	@Override
	protected void onPostExecute(String result) {
		if (progressDialog.isShowing()) {
			try {
				progressDialog.dismiss();
			} catch (Exception e) {
			}
		}


	}

}
